<?php
// 应用公共文件

/**
 * 随机生成要求位数个字符
 * @param length 规定几位字符
 */
function getRandChar($length = 1){
    $str = null;
    $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";//大小写字母以及数字
    $max = strlen($strPol)-1;

    for($i=0;$i<$length;$i++){
        $str.=$strPol[rand(0,$max)];
    }
    return $str;
}

/**
 * 获取微秒级时间戳
 * @return string
 * @author Freedom <266163@qq.com>
 */
function getMicroSecondsTimestamp (){
    $time = microtime();
    return substr($time,11,10).str_pad(substr($time,0,8) * 1000000,6,"0",STR_PAD_LEFT);
}

function get_uploadfile_name(){
    // 2021/01/25/af/asdasdasdasdq2edqwdasdasdasas
    $dir = date('Y/m/d') . '/' . getRandChar(2);
    $fielname = md5(getMicroSecondsTimestamp());

    return $dir . '/' . $fielname;
}
